// import 'package:appsflyer_sdk/appsflyer_sdk.dart';
import 'package:bitcoin_mine/controllers/contract_service_controller.dart';
import 'package:bitcoin_mine/services/in_app_purchase_service.dart';
import 'package:bitcoin_mine/services/token_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'l10n/app_localizations.dart';
import 'theme/app_theme.dart';
import 'routes/app_routes.dart';
import 'controllers/main_controller.dart';
import 'controllers/animation_controller.dart' as balance_animation;
import 'controllers/privacy_controller.dart';
import 'services/auth_service.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 初始化服务
  Get.put(MainController());
  Get.put(AuthService());
  Get.put(InAppPurchaseService());
  await initApp();

  runApp(const BitcoinMineApp());
}

Future<void> initApp() async {
  // 初始化Loggy
  // Loggy.initLoggy(logPrinter: const PrettyPrinter(showColors: true));
  // await Purchases.setDebugLogsEnabled(true);

  //todo: 初始化AppLovinMAX
  // ULgr3HAVzDQLN2CO3QT1Kgvq9K8176Mx55PWtdmbEk2bz83pGR_LRIb6XkAmzttQcZZw2evWL9ui3imnq6FOtl

  // AppLovinMAX.setVerboseLogging(true);
  // MaxConfiguration? sdkConfiguration = await AppLovinMAX.initialize(
  //   "ULgr3HAVzDQLN2CO3QT1Kgvq9K8176Mx55PWtdmbEk2bz83pGR_LRIb6XkAmzttQcZZw2evWL9ui3imnq6FOtl",
  // );
  // if (sdkConfiguration != null) {
  //   Global.isAppLovinMAXInitialized = true;
  //   // AppLovinMAX.setMediationProvider(MediationProvider.max);
  //   print('AppLovinMAX初始化成功');
  // } else {
  //   print('AppLovinMAX初始化失败');
  // }
}

class BitcoinMineApp extends StatelessWidget {
  const BitcoinMineApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(414, 896),
      builder: (context, child) {
        return GetMaterialApp(
          title: 'Bitcoin Mine',
          theme: AppTheme.darkTheme,
          localizationsDelegates: AppLocalizations.localizationsDelegates,
          supportedLocales: AppLocalizations.supportedLocales,
          locale: const Locale('en', ''), // 默认英语
          initialRoute: AppRoutes.splash,
          getPages: AppRoutes.routes,
          debugShowCheckedModeBanner: false,
        );
      },
    );
  }
}
